package edu.hawaii.server;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.List;
import edu.hawaii.client.Semester;

/**
 * Test class to figure things out.
 * 
 * @author Kiet
 */
public class ObjectTest {

  
/**
 * Main function.
 * 
 *  @param args The string array from comand line or any passed in parameters.
 *  @throws Exception not sure what exception it throws.
 */
  public static void main(String[] args) throws Exception {
    
    Connection conn = null;
    CallableStatement cstmt = null;
    ResultSet Rs = null;
    
      try {
        //      Establish the connection
        conn = DatabaseConnector.getConnection();
        
        // pass parameter to the "..." stored procudure. For security reasons,
        // I removed the stored procedure names. Email me at kiet@hawaii.edu 
        // for more information.
        //cstmt = conn.prepareCall("" +
        //    "{call dbo.ReportServer_EnrollmentManagement_ViewAvailableSeatsBySection_proc(?, "
         //   + "?, ?, ?, ?, ?, ?)}");
        
        cstmt = conn.prepareCall(""
            + "{call dbo.ReportServer_Semester_proc()}");
        
        //cstmt.setString(1, "800"); // 500
        //cstmt.setString(2, "MAN"); // MAN
        //cstmt.setString(3, "200710"); // 200730
        //cstmt.setString(4, "%"); // 10
        //cstmt.setInt(5, 1); // 1000
        //cstmt.setInt(5, 1000); // 1000
        //cstmt.setString(6, "ICS"); // ICS 
        //cstmt.setString(7, "%"); // %
       
        
        // execute the stored procudure
        Rs = cstmt.executeQuery();
        //List result = ObjectFactory.convertsToObjects(Rs, AvailableSeatsBySection.class);
        List result = ObjectFactory.convertsToObjects(Rs, Semester.class);
        for (Iterator itr = result.iterator(); itr.hasNext();) {
          //CourseNameByCampus t = (CourseNameByCampus) itr.next();
          //AvailableSeatsBySection t = (AvailableSeatsBySection) itr.next();
          Semester t = (Semester) itr.next();
          System.out.println("Topping " + t.getSemesterText() + t.getSemesterKey());
        }
      }
      catch (Exception e) {
        e.printStackTrace();
        
      }
      finally { //closing all database stuff
        if (Rs != null) {
          try {
            Rs.close(); 
          }
          catch (Exception e) {
            //
          }
        }
        
        if (cstmt != null) {
          try {
            cstmt.close();
          }
          catch (Exception e) {
            //
          }
        }
        
        if (conn != null) {
          try {
            conn.close();
          }
          catch (Exception e) {
            //
          }
        }    
      }
  }

}
